﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ScarEngine
{
    public class DrawableComponent : Component
    {
        
        public Color Color;
        public float Scale;
        public Texture2D Texture;


        public DrawableComponent()
            :base()
        {
            MasterManager.GraphicsManager.RegisterComponent(this);
            Color = new Color(255, 255, 255, 255);
            Scale = 1f;
            Texture = Game1.Game.Content.Load<Texture2D>("Textures\\OnePixelWhite");
        }


        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            PositionalComponent P = Object.Get<PositionalComponent>();
            Rectangle R = new Rectangle((int)P.Position.X,(int)P.Position.Y,(int)Texture.Width,(int)Texture.Height);
            Vector2 O = new Vector2(Texture.Width / 2, Texture.Height / 2);

            spriteBatch.Draw(Texture, P.Position, null, Color, P.Rotation, O, Scale, SpriteEffects.None, 0f);

        }


        #region Core
        public override void Delete()
        {
            MasterManager.GraphicsManager.UnRegisterComponent(this);
            base.Delete();
        }

        public override void Prerequisites()
        {
            if (Object.HasComponent<PositionalComponent>() == false)
            {
                Object.Add<PositionalComponent>("Position");
            }
            base.Prerequisites();
        }

        #endregion


    }
}